package net.esj.basic.core.business.web.interceptor;

import net.esj.basic.core.view.tools.ActionContext;
import net.esj.basic.pojo.op.Operator;
import net.esj.basic.service.provider.UserRuleProvider;
import net.esj.basic.core.business.aware.op.OperatorAware;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class OperatorProvideInterceptor extends
		AbstractInterceptor {

	private String operatorType;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Object action = invocation.getAction();
		//String opty  = (String)ActionContext.getRequest().getAttribute(OperatorTypeAware.OPERATOR_TYPE_KEY);
		if(action instanceof OperatorAware){
			Operator operator = UserRuleProvider.getSessionUser(ActionContext.getSession(), operatorType);
			OperatorAware aware = (OperatorAware)action;
			aware.setOperator(operator);
			/*if(StringUtils.hasText(opty)){
				aware.setOpType(opty);
			}else{
				aware.setOpType(getOperatorType(aware));
			}*/
		}
		return invocation.invoke();
	}

	//public abstract String getOperatorType(OperatorAware aware);

	public void setOperatorType(String operatorType) {
		this.operatorType = operatorType;
	}
	
	
}
